<template>
	<view class="container">
		<view class="mdlist">

			<view class="mdlist_dl" v-for="(item,index) in shops" :key="item.id">
				<view class="mdlist_dt" @click="select" :data-index="index">
					<view class="mdlist_title">{{item.name}}</view>
					<view class="mdlist_txt">{{item.address}}</view>
					<view class="mdlist_txt">营业时间：<text>{{item.times}}</text></view>
				</view>
				<view class="mdlist_dd">
					<view class="mdlist_dbtn" @click="callme" :data-index="index"><text
							class="iconfont icon-dianhua"></text></view>
					<view class="mdlist_dbtn" @tap="map" :data-index="index"><text class="iconfont icon-daohang"></text>
					</view>
				</view>
			</view>


		</view>
	</view>
</template>

<script>
	import API from "@/common/api.js";
	//#ifdef WEB
	import jweixin from 'weixin-js-sdk'
	//#endif
	export default {
		data() {
			return {
				shops: []
			}
		},
		onLoad() {
			var $this = this
			API.post("common/shoplist", {}).then((res) => {
				if (res.code == 1) {
					$this.shops = res.data
				}
			})
		},
		methods: {
			select(e) {
				var index = e.currentTarget.dataset.index;
				uni.setStorageSync("shopid", this.shops[index].id)
				uni.reLaunch({
					url: "/pages/index/index"
				})
			},
			callme(e) {
				var index = e.currentTarget.dataset.index;
				uni.makePhoneCall({
					phoneNumber: this.shops[index].mobile
				});
			},
			map(e) {
				var $this = this
				var index = e.currentTarget.dataset.index;
				if (this.shops[index].jing && this.shops[index].wei) {
					// #ifdef WEB
					var surl = encodeURIComponent(window.location.href.split('#')[0]);
					API.post("common/jweixin", {
						surl: surl
					}).then((res) => {
						if (res.code == 1) {
							jweixin.config({
								debug: res.data.debug,
								appId: res.data.appId,
								timestamp: res.data.timestamp,
								nonceStr: res.data.nonceStr,
								signature: res.data.signature,
								surl: res.data.url,
								jsApiList: res.data.jsApiList
							});

							jweixin.ready(function() {
								jweixin.openLocation({
									latitude: Number($this.shops[index].wei),
									longitude: Number($this.shops[index].jing),
									name: $this.shops[index].name || '',
									address: $this.shops[index].address
								});

							});

						}
					})
					// #endif
					// #ifndef WEB
					uni.openLocation({
						latitude: Number($this.shops[index].wei),
						longitude: Number($this.shops[index].jing),
						name: $this.shops[index].name || '',
						address: $this.shops[index].address
					});
					// #endif
				}

			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #f8f9fa;
	}

	.mdlist {
		padding: 30rpx;
	}

	.mdlist_dl {
		background: #fff;
		width: 100%;
		display: flex;
		padding: 24rpx 30rpx 30rpx;
		box-sizing: border-box;
		position: relative;
		border-radius: 10rpx;
		margin-bottom: 28rpx;
		overflow: hidden;
	}

	.mdlist_dt {
		flex: 1;
	}

	.mdlist_title {
		font-size: 32rpx;
		line-height: 60rpx;
	}

	.mdlist_title text {
		display: inline-block;
		margin-left: 10rpx;
		background: #f7b071;
		padding: 0 10rpx;
		border-radius: 8rpx;
		color: #fff;
		font-weight: normal;
		font-size: 24rpx;
	}

	.mdlist_txt {
		width: 100%;
		display: flex;
		margin-top: 12rpx;
		color: #999;
	}

	.mdlist_txt text {
		color: #555;
	}

	.mdlist_dd {
		margin-left: 20rpx;
	}

	.mdlist_dbtn {
		display: inline-block;
		line-height: 40rpx;
		padding: 18rpx 10rpx;
		margin-left: 20rpx;
	}

	.mdlist_dbtn text {
		font-size: 30rpx;
	}
</style>